var eg={version:20120221};
function Version(){
	alert('Version:'+eg.version);
}

/* 去除空格 */
String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
/* 用于input标签输入数据时检查，强制性转祛除非法字符    \ / : * ? " < > | & % '~  */
function fnInputFilterFCC(obj)   
{   
	var reg = /[\\\/\*\?"<>,|&%'`~]/g;
	obj.value = obj.value.replace(reg,"");   
}
function fnInputFilterFCC2(obj)   
{   
	var reg = /[\\\/\*\?"<>|&%'`~]/g;
	obj.value = obj.value.replace(reg,"");   
}

function fnInputFilterFCC3(obj)   
{   
	var reg = /[\\\/\\?"<>|&%'`~]/g;
	obj.value = obj.value.replace(reg,"");   
}

var fnFCC = fnInputFilterFCC;

/*输入非中文字符*/
function fchinese(obj){
	var reg = /[\u4e00-\u9fa5]/g;
	obj.value = obj.value.replace(reg,"");  
}

/* 用于input标签输入数据时检查，强制性转祛除非法字符   只能是数字 */
function fnInputFilterFCCN(obj)   
{   
	var reg = /[\D]/g;
	obj.value = obj.value.replace(reg,"");   
}

/*只能输入字母、数字、下划线和点*/
function fnInputFilterFCCN3(obj){
	var reg = /[^a-z0-9_.]/g;
	obj.value = obj.value.replace(reg,"");
}

var fnFCCN = fnInputFilterFCCN;
/* 是否为空 */
function isNull(_sVal)
{
	return ((typeof _sVal == "undefined") || (_sVal == null) || (_sVal == ""));
}


function clearNoNum(event,obj){ 
    //响应鼠标事件，允许左右方向键移动 
    event = window.event||event; 
    if(event.keyCode == 37 | event.keyCode == 39){ 
        return; 
    } 
    //先把非数字的都替换掉，除了数字和. 
    obj.value = obj.value.replace(/[^\d.]/g,""); 
    //必须保证第一个为数字而不是. 
    obj.value = obj.value.replace(/^\./g,""); 
    //保证只有出现一个.而没有多个. 
    obj.value = obj.value.replace(/\.{2,}/g,"."); 
    //保证.只出现一次，而不能出现两次以上 
    obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$","."); 
} 

function checkNum(obj){ 
    //为了去除最后一个. 
    obj.value = obj.value.replace(/\.$/g,""); 
} 

function chkmail(val)
{
	var $exps = new RegExp("^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$","g");
	
	if (!$exps.test(val)){
		return false;
	}else{
		return true;
	}
}


/*---------------------得到累计表格数据begin---------------------*/
function fnZGetFields(_args)
{
	var returns = [];
	var bRename = false;
	var beachF = false;
	var splits = '';
	if(_args.rename){
		bRename = true;
	}
	if(_args.eachFields){
		beachF = true;
	}
	if(_args.splits){
		splits = _args.splits;
	}

	for(var ii=0;ii<=_args.nums;ii++)
	{ 
		if(eval('document.getElementById("'+_args.fields[0] + splits + ii+'")'))
		{
			this.sn = ii;																					 
			var oTemp = new function(){
						if(beachF){
							for(var pp=0;pp<(_args.eachFields.length/2);pp++){
								eval('this.'+_args.eachFields[pp*2]+' = "'+_args.eachFields[pp*2+1]+'"');
							}
						}
						for(var kk=0;kk<_args.fields.length;kk++)
						{
							if(eval('document.getElementById("'+_args.fields[kk] + splits + ii+'")')){
								var this_id = _args.fields[kk] + splits + ii;
								if(bRename){
									eval('this.'+_args.rename[kk]+' = fnZGetFields_val({id:"'+this_id+'",type:_args.fieldtype[kk]})');
								}else{
									eval('this.'+_args.fields[kk]+' = fnZGetFields_val({id:"'+this_id+'",type:_args.fieldtype[kk]})');
								}
							}
						}
					};
			returns.push(oTemp);
		}
	}
	return returns;
}
function fnZGetFields_val(_args)
{
	var returns = null;
	switch(_args.type)
	{
		case 'select':
		case 'textarea':
		case 'hidden':
		case 'text':
			returns = $('#'+_args.id).val();
			break;
		case 'checkbox':
			if(document.getElementById(_args.id).checked){
				returns = '1';
			}else{
				returns = '0';
			}
			break;
		case 'nodetext':
			if(document.getElementById((_args.id)).firstChild){
				returns = document.getElementById((_args.id)).firstChild.nodeValue;
			}else{
				returns='';
			}
			break;
		default:
			returns = $('#'+_args.id).val();
			break;
	}
	
	return returns;
}
/*---------------------得到表格数据end---------------------*/

/**
*设置日期选择
*/
function fnSetSltDate(_Field,_button,_all){
	var dateFormat = '%Y-%m-%d';
	if(_all=='showtime'){
		dateFormat = "%Y-%m-%d %H:%M:%S";
	}
	
	Calendar.setup({
		inputField:_Field,
		button:_button, 
		ifFormat:dateFormat
		//align:"Tl", 
	});
}
/* 是否有dom节点 */
function fnDom(element){
	if(typeof element == 'string'){
		element = document.getElementById(element);
	}	
	if(element)
		return true;
	else
		return false;
}
   
/* 锁定一批DOM节点 */
function fnGLock(a_elements){
	for(var ii=0;ii<a_elements.length;ii++){
		var elements = a_elements[ii];
		if(typeof a_elements[ii] == 'string'){
			elements = document.getElementById(a_elements[ii]);
		}
		switch(elements.nodeName){
			case 'INPUT':
				if(elements.getAttribute('type') == 'text'){
					$(elements).attr({"readonly":"readonly"});
				}else{
					$(elements).attr({"disabled":"disabled"});
				}
			case 'TEXTAREA':
				$(elements).attr({"readonly":"readonly"});
				$(elements).addClass('textareadisable');
				break;
			default:
				$(elements).attr({"disabled":"disabled"});
		}	
	}
}
/* 解锁一批DOM节点 */
function fnGUnLock(a_elements){
	for(var ii=0;ii<a_elements.length;ii++){
		var elements = a_elements[ii];
		if(typeof a_elements[ii] == 'string'){
			elements = document.getElementById(a_elements[ii]);
		}
		switch(elements.nodeName){
			case 'INPUT':
				if(elements.getAttribute('type') == 'text'){
					$(elements).attr({"readonly":""});
				}else{
					$(elements).attr({"disabled":""});
				}
			case 'TEXTAREA':
				$(elements).attr({"readonly":""});
				$(elements).removeClass('textareadisable');
				break;
			default:
				$(elements).attr({"disabled":""});
		}
	}
}
/* 锁定一批IMG节点 */
function fnGLockImg(id){
	$('#'+id+' img').each(function(){
		 $(this).get(0).setAttribute("style","display:none;");
		 $(this).get(0).style.display = "none";
	});
}
/* 解锁一批IMG节点 */
function fnGUnLockImg(id){
	$('#'+id+' img').each(function(){
		 $(this).get(0).setAttribute("style","display:;");
		 $(this).get(0).style.display = "";
	});
}
/**
* json返回错误处理
* json串返回的格式为 
*{"success":"1","msg":"保存成功.","id":"1"}
*{"success":"0","msg":"保存失败."}	
*/ 
function errorHandler(msg){
	var error=JSON.decode(msg);
	if(typeof(error)=='object'){
		if(error['success']==1){
			if(error['msg']){
				alert(error['msg']);
			}
			return error;
		}else{
			if(error['msg']){
				alert(error['msg']);
			}
			return false;
		}
	}else{
		alert('11111');
		alert(msg);
		return false;
	}
}


function errorHandler_new(msg){
	var error=JSON2.parse(msg);
	if(typeof(error)=='object'){
		if(error['success']==1){
			if(error['msg']){
				alert(error['msg']);
			}
			return error;
		}else{
			if(error['msg']){
				alert(error['msg']);
			}
			return false;
		}
	}else{
		alert(msg);
		return false;
	}
}

function errorHandler2(msg){
	var error=EJSON.decode(msg);
	if(typeof(error)=='object'){
		if(error['success']==1){
			if(error['msg']){
				errorHandlerAlert(error['msg']);
			}
			return error;
		}else{
			if(error['msg']){
				errorHandlerAlert(error['msg']);
			}
			return error;
		}
	}else{
		errorHandlerAlert(msg);
		return false;
	}
}

function errorHandlerAlert(s){
	alert(s);
}
/* 最简单的json解码函数 */
var EJSON=new function(){
	this.decode=function(msg){
		msg=msg.replace(/^\s+|\s+$/g, '');
		if(msg.match(/^\{.*\}$/g)){
			return eval('('+msg+')');
		}else{
			return msg;	
		}
	};
};
/* 得到select的值和html，包括单个的和多个的 */
function fnGetSltHtml(_objstr){
	return $('#'+_objstr+' option:selected').get(0).innerHTML;
}
function fnGetSltValue(_objstr){
	return $('#'+_objstr).val();
}
function fnGetMSltHtml(_objstr){
	var returns = [];
	var i=0;
	$('#'+_objstr+' option:selected').each(function(){	    
			returns[i++] = this.text;
	});
	return returns;	
}
function fnGetMSltValue(_objstr){
	var returns = [];
	var i=0;
	$('#'+_objstr+' option:selected').each(function(){	    
			returns[i++] = this.value;
	});
	return returns;	
}
/* 通过id选中selet标签 */
function fnSelected(_id){
	if($.browser.msie){
		if(fnDom(_id)){
			document.getElementById(_id).setAttribute('selected','selected');
		}	
	}else{
		$('#'+_id).attr({'selected':'selected'});
	}
}
/* 得到checkde的值 */
function fnGetCheckBox(element){
	if(typeof element == 'string'){
		element = document.getElementById(element);
	}
	if(element.checked){
		returns = '1';
	}else{
		returns = '0';
	}
	return returns;
}
/* 得到checkde的值 */
function fnSetCheckBox(element,val){
	if(typeof element == 'string'){
		element = document.getElementById(element);
	}
	element = $(element);
	if(val == '1'){
		element.attr('checked',true);
	}else{
		element.attr('checked',false);
	}
}
/* 是否是数字，包括有小数的和没小数的 */
function fnNum(val){
	if(isNaN(val)){
		return false;
	}else{
		var pf_temp = parseFloat(val);
		if(isNaN(pf_temp)){
			return false;
		}else{
			return true;
		}
	}
}
/* 设置小数位的 */
function fnDec(val,dig){
	var temp = 0;
	if(fnNum(val)){
		temp = parseFloat(val);
	}
	return temp.toFixed(dig);	
}
function strToNum(val){
	if(!fnNum(val)){
		return 0;
	}else{
		return parseFloat(val);
	}
}
/*拷贝数组*/
function fnCpArray(aCopyObj)
{
 	return aCopyObj.concat([]);
}
function ebox(){
	alert(arguments[0]);
}
/* 设置select的通用的 */
function fnMakeSelect(element,selects){
	/* selects对象格式为：
			selects = {
				val:-1,
				opt:[{"id":"-1","name":"男"},{"id":"1","name":"女"}
				group:''(group可有可无)
		 }
	*/
	if(typeof element == 'string'){
		element = document.getElementById(element);
	}
	element = $(element);
	
	var temp_id = element.attr('id');
	var htmls = '';
	var slt_id = '';
	var group='';
	var group_first = true;
	
	for(var i=0; i < selects.opt.length ; i++){
		var opts = selects.opt[i];
		var names = opts.name;
		if(selects.group){
			if(opts[selects.group] !== group){
				if(group_first){
					htmls += '<optgroup label="'+opts[selects.group]+'">';
				}else{
					htmls += '</optgroup><optgroup label="'+opts[selects.group]+'">';
				}
			}
			group = opts[selects.group];
			group_first = false;
			//names = group + '-' + names;
			names = names;
		}
		
		var cur_id = '';
		if(selects.val == opts.id){
			slt_id = 'e-mkselect-' + (new Date()).getTime()+'-'+temp_id;
			cur_id = ' id= "'+slt_id+'" ';
		} 
		htmls += '<option value="'+opts.id+'" '+cur_id+'>'+names+'</option>';
	}
	if(selects.group){
		htmls += '</optgroup>';
	}
	element.html(htmls);

	if (slt_id){
		fnSelected(slt_id);
	}
}
/* 只要有jquery的ajax时，右上角提示正在加载图标 */
function showLoading(){
	var whether = true;
	var pic = 'themes/default/assets/misc/images/new/103.gif';
	var msg = '<font style="font-family:宋体;font-weight:bold;" color="#8B97FC">处理中,请稍候...</font>';
	if(typeof arguments[0] != "undefined"){
		msg = arguments[0];
	}
	if(document.getElementById('emvc-ajaxloading-div')){
		$('#emvc-ajaxloading-div').remove();
	}
	
	/*遮罩层 css*/
	var ajaxovlay = "filter:alpha(opacity=10);-moz-background-clip:border";
		ajaxovlay += "-moz-background-inline-policy:continuous";
		ajaxovlay += "-moz-background-origin:padding;";
		ajaxovlay += "background:#000000 none repeat scroll 0 0;";
		//ajaxovlay += "height:" + document.body.clientHeight + "px;";
		ajaxovlay += "height:790px;";
		ajaxovlay += "left:0;";
		ajaxovlay += "opacity:0.09;";
		ajaxovlay += "position:absolute;";
		ajaxovlay += "top:0;";
		ajaxovlay += "width:100%;";
		ajaxovlay += "z-index:99998;display:none;";

	var outStr = '<div id="ajax_ovlay" style="'+ajaxovlay+'"></div><div id="emvc_ajaxloading_div" style="border: 1px solid rgb(152, 177, 200);';
	outStr += 'position:absolute;margin-left:50%;left:-50px;margin-top:25%;z-index:1000000;background-color:#ffffff;';
	outStr += 'padding:5px;display:none;"><img src="'+pic+'" height="50px" width="100px" style="padding:5px;"><br>';
	outStr += '<span id="emvc_ajaxloading_msg">'+msg+'</span></div>';
	
	/*被卷去的高度，设置一下相对的top，让他始终可以看得到*/

	$(document.body.firstChild).before(outStr);
	$("#emvc_ajaxloading_div").ajaxStart(function(){																									
		var top = (document.documentElement.scrollTop);
		top = top+'px'; 
		$(this).css('top',top);

		$(this).show();
		$('#ajax_ovlay').show();
		$(this).css('color','black');
		$('#emvc_ajaxloading_msg').html(msg);
	});
	$("#emvc_ajaxloading_div").ajaxError(function(){

		$(this).show();
		$('#ajax-ovlay').show();
		$(this).css('color','red');
		$('#emvc_ajaxloading_msg').html('操作错误，请联系管理员...');
	});
	$("#emvc_ajaxloading_div").ajaxStop(function(){ 
			
		var pthis = this;
		
		setTimeout(function(){
			
			$('#ajax_ovlay').hide();

			$(pthis).hide();
			
		},1000);
			

	});
}
/* 打开一个窗体默认的参数,主要是窗体居中用 */
function winOpenArgs(){
	var width=800;
	var height=400;
	if(arguments[0]) width = arguments[0];
	if(arguments[1]) height = arguments[1];
	return 'width='+width+',height='+height+',resizable=1,scrollbars=1,left='+(screen.width-width)/2+',top='+(screen.height-height)/2;
}
/*刷新父窗体的DS*/
function openerReloadDs(args){
	if(window.opener){
		if( typeof args == 'string'){ 
			args = [].push(args);
		} 
		for(var i=0;i<args.length;i++){
			if(eval('window.opener.'+args[i])){
				eval('window.opener.'+args[i]+'.reload()');
			}
		}
	}
}
/*验证电话号码*/
function checkPhone(inputVal){
	var p1 = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;
	return p1.test(inputVal);
}
/* 提示确认通用函数 */
function fnConfirm(_obj){
	var dft = {
		str:'......?',
		func_true:function(){},
		func_false:function(){}
	};
	_obj = jQuery.extend(dft, _obj);
	var temp = window.confirm(_obj.str);
	if(temp){
		_obj.func_true();
	}else{
		_obj.func_false();
	}
}
/* 关联精确查找 */
function exactLoad(args){
	var R = $.extend({ button:false,	params:{}	},args || {} );
	$('#'+R.id).keypress(function(e){if(e.keyCode==13){
		if(typeof R.params == "function" ){$.post(R.url,$.extend({q: $('#'+R.id).val()},R.params()),function(e){R.func(e);});}else{$.post(R.url,$.extend({q: $('#'+R.id).val()},R.params),function(e){R.func(e);});}
	}});
	if(R.button){ $('#'+R.button).bind('click',function(){
		if(typeof R.params == "function" ){$.post(R.url,$.extend({q: $('#'+R.id).val()},R.params()),function(e){R.func(e);});}else{$.post(R.url,$.extend({q: $('#'+R.id).val()},R.params),function(e){R.func(e);});}
	});}
}
function stopBubble(e) {if(e && e.stopPropagation ) e.stopPropagation(); else window.event.cancelBubble = true;}
function stopDefault( e ) {
	if( e && e.preventDefault )
		e.preventDefault();
	else
		window.event.returnValue = false;
	return false;
}
/* 时间处理函数*************************************************************************** */
/*格式化日期原型控制  yyyy-M-dd*/
Date.prototype.eformat = function(format)
{
	var o = {
		"M+" : this.getMonth()+1, //month
		"d+" : this.getDate(),    //day
		"h+" : this.getHours(),   //hour
		"m+" : this.getMinutes(), //minute
		"s+" : this.getSeconds(), //second
		"q+" : Math.floor((this.getMonth()+3)/3),  //quarter
		"S"  : this.getMilliseconds() //millisecond
	}
	if(/(y+)/.test(format)){
		format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
	}	
	for(var k in o){
		if(new RegExp("("+ k +")").test(format)){
			format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
		}
	}		
	return format;
}
/*字符串日期转化为日期对像*/
function toDateObj(strDate){
	return new Date(Date.parse(strDate.replace(/-/g,'/')));
}

/* 是否为日期格式的字符串YYYY-MM-DD */
function isDateString(sDate){
	var exps = new RegExp("^\\d{4}\\-\\d{1,2}\\-\\d{1,2}$","g");
	if(!exps.test(sDate)) return false;
	var iaMonthDays = [31,28,31,30,31,30,31,31,30,31,30,31];
	var iaDate = sDate.toString().split("-");
	var year 	= parseFloat(iaDate[0]);
	var month = parseFloat(iaDate[1]);
	var day		= parseFloat(iaDate[2]);
	if (year < 1900 || year > 2100) return false
	if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1]=29;
	if (month < 1 || month > 12) return false
	if (day < 1 || day > iaMonthDays[month - 1]) return false
	return true
}
function today(){
	return (new Date()).eformat('yyyy-M-dd');
}
function now(){
	return (new Date()).eformat('yyyy-M-dd hh:mm:ss');
}
/* 转字符串为日期对象，可以是yyyy-mm-dd 也可以是yyyy-mm-dd hh:ii:ss */
function strToDate(_str){
	var _y='',_m='',_d='',_h='',_i='',_s='';
	_y = (_str.substring(0,_str.indexOf ('-')));//y
	_m = (_str.substring(_str.indexOf ('-')+1,_str.lastIndexOf ('-')));//m
	_d = (_str.substring(_str.lastIndexOf ('-')+1));//d	
	if(_str.indexOf (' ') > 0){ 
		_d = (_str.substring(_str.lastIndexOf ('-')+1,_str.indexOf (' ')));//d	
		_h = (_str.substring(_str.indexOf (' ')+1,_str.indexOf (':')));//h
		_i = (_str.substring(_str.indexOf (':')+1,_str.lastIndexOf (':')));//i
		_s = (_str.substring(_str.lastIndexOf (':')+1));//s
 	}
	var eval_str = ' new Date("'+_y+'","'+(_m-1)+'","'+_d+'"';
	if(_h != ''){
		eval_str += ',"'+_h+'"';
		eval_str += ',"'+_i+'"';
		eval_str += ',"'+_s+'"';
	}
	return eval(eval_str+');');
}
/* 时间比较函数 */
function dateDiff(interval, b_date, e_date) {
	var returns=false;
	if(typeof b_date == "string"){
		b_date =strToDate(b_date);
	}
	if(typeof e_date == "string"){
		e_date =strToDate(e_date);
	}
	interval = interval.toLowerCase();
	switch(interval){
		case 'y':
			returns = ((e_date- b_date)/86400000/365);
			break;
		case 'm':
			returns = (e_date.getMonth()+1)+((e_date.getFullYear()-b_date.getFullYear())*12) - (b_date.getMonth()+1);
			break;
		case 'd':
			returns = ((e_date- b_date)/86400000);
			break;
		case 'h':
			returns = ((e_date- b_date)/(3600000));
			break;
		case 'i':
			returns = ((e_date- b_date)/(60000));
			break;
		case 's':
			returns = (e_date- b_date)/1000;
			break;
		default:
			returns = ((e_date- b_date)/86400000);
			break;
	}
	return Math.floor(returns);
}
/*在_obj基础上再加几天*/
function addDay(_obj,_num){
	var returns = null;
	returns = new Date(_obj.getTime() + (3600000*24*_num));
 	return returns;
}
/*在_obj基础上再加几周*/
function addWeek(_obj,_num){
	var returns = null;
	returns = new Date(_obj.getTime() + (3600000*24*7*_num));
 	return returns;
}
/*得到这周的第一天*/
function getWeekFirst(_obj){
	return addDay(_obj,1 - _obj.getDay());
}
/*得到这周的最后一天*/
function getWeekLast(_obj){
	return addDay(_obj,7 - _obj.getDay());
}
/*在_obj基础上再加几月*/
function addMonth(_obj,_num){
	var returns = null;
	var obj = new Date(_obj.getTime());
	returns = new Date(obj.setMonth(obj.getMonth()+_num));
 	return returns;
}
/*得到这个月份的第一天*/
function getMonthFirst(_obj){
	var obj = new Date(_obj.getTime());
	returns = new Date(obj.setDate(1));
 	return returns;
}
/*得到这个月份的最后一天*/
function getMonthLast(_obj){
	var returns = null;
	returns = new Date(_obj.getFullYear(),(_obj.getMonth()+1),0);
 	return returns;
}
/*在_obj基础上再加几年*/
function addYear(_obj,_num){
	return addMonth(_obj,_num*12);
}
/*得到这年的第一天*/
function getYearFirst(_obj){
	_obj.setMonth(0);
	_obj.setDate(1);
	return _obj;
}
/*得到这年的最后一天*/
function getYearLast(_obj){
	 return addDay(getYearFirst( addYear(_obj,1) ),-1);
}
/*在_obj基础上再加几个季度*/
function addQuarter(_obj,_num){
	return addMonth(_obj,_num*3);
}
/*得到这个季度的第一天*/
function getQuarterFirst(_obj){
	var returns = null;
	switch((_obj.getMonth()+1)){
		case 1:
		case 2:
		case 3:
			returns = new Date(_obj.getFullYear(),0,1);
			break;
		case 4:
		case 5:
		case 6:
			returns = new Date(_obj.getFullYear(),3,1);
			break;
		case 7:
		case 8:
		case 9:
			returns = new Date(_obj.getFullYear(),6,1);
			break;
		case 10:
		case 11:
		case 12:
			returns = new Date(_obj.getFullYear(),9,1);
			break;
	}
	return returns;
}
/*得到这个季度的最后一天*/
function getQuarterLast(_obj){
	var returns = null;
	switch((_obj.getMonth()+1)){
		case 1:
		case 2:
		case 3:
			returns = new Date(_obj.getFullYear(),3,0);
			break;
		case 4:
		case 5:
		case 6:
			returns = new Date(_obj.getFullYear(),6,0);
			break;
		case 7:
		case 8:
		case 9:
			returns = new Date(_obj.getFullYear(),9,0);
			break;
		case 10:
		case 11:
		case 12:
			returns = new Date(_obj.getFullYear(),12,0);
			break;
	}
	return returns;
}
/* 时间处理函数 */ 
/*动态产生元素 */
//var show_div_R={a:'dsdf'};//弹出窗体的全局变量
function show_div(args){
	var times=+new Date();
	var R = {
		background_id:'background_div_'+times,
		div_id:'inner_div_'+times,
		title_id:'title_div_'+times, 
		backgroundcolor:'#999999',
		frames_name:'msg_frame'+times,
		width:400,
		height:300,
		url:'',
		title:'站内信管理',
		content:'',//消息提示
		func:function(){},
		func2:function(){},
		title_height:20,
		datasources:'',/*数据内容*/
		selecthide:true,
		allowMove:false/*是否允许拖动窗口*/
	};
	jQuery.extend(R,args);
	show_div_R = jQuery.extend({},R);
 
	//	var parent_div_color='#999999'
	//	var title_height=20;
	var _left=document.body.clientWidth/2-R.width/2;
	var _top=document.body.clientHeight/2-R.height/2;
	var _width = document.body.clientWidth;
	var _height = screen.height;
	
	if (screen.height < document.body.clientHeight){
		_height = document.body.clientHeight;
	}
	
	//alert(document.body.clientHeight);
	//	var div_id=+new Date();
	//	if(!title){
	//		var title='短信管理';
	//	}
	//	var title_html='<input type="button" value="关闭" onclick="remove_child(\'test_div\')">';
	//	<input type="image" src="'+themeUrl+'misc/images/cross.png" style="cursor:pointer;z-index:500001;"  id="remove_img" />
	//div_height=screen.height>document.body.offsetHeight?screen.height:document.body.offsetHeight;
	var htmls  = '<div style="position:absolute;top:0px;left:0px;width:'+_width+'px;height:'+_height+'px;';
		 htmls += 'z-index:49999;background-color:gray;opacity:0.75;filter:Alpha(Opacity=75);" id="'+R.background_id+'"></div>';
		 htmls += '<div style="position:absolute;top:80px;left:'+_left+'px;top:'+_top+'px;width:'+R.width+'px;height:'+R.height+'px;';
	    htmls += 'background-color:#FBFBFA;border:3px #525252 solid;z-index:50000" id="'+R.div_id+'"><div id="'+R.title_id+'" ';
	    htmls += 'style="background-color:#E2EAF8;height:20px;padding:8px;cursor:move;color:#1A6DC1;margin-bottom:5px" ';
	    htmls += '>'+R.title+'<input type="text" id="show_div_temp" style="display:none"/>';
	    htmls += '<div style=" position:absolute;top:8px;right:8px;cursor:pointer;" id="remove_img">';
	    htmls += '关 闭</div></div><div id="iframe_div"><iframe style="top:'+(R.width+R.title_height)+'px; left:'+R.height+';" ';
	    htmls += 'src="'+R.url+'" height="'+(R.height-R.title_height-30)+'px" width="100%" ';
	    htmls += 'frameborder="no" border="0" marginwidth="0" marginheight="0"  name="'+R.frames_name+'"></iframe></div></div>';
	
	if (R.selecthide){
		$('select').hide();
	}
	
	$(document.body.firstChild).before(htmls);
	if ($.browser.msie) {window.parent.frames[R.frames_name].location.reload(); }
	
	/*默认不允许拖动*/
	if(R.allowMove){
		
		$('#'+R.title_id).mousedown(function (event){ 
			$('#'+R.div_id).css('opacity','0.75'); 
			$('#'+R.div_id).css('filter','Alpha(Opacity=75)'); 
			var x=event.clientX+document.body.scrollLeft;
			var y=event.clientY+document.body.scrollTop;
			var old_top=parseInt($('#'+R.div_id).css('left'));
			var old_left=parseInt($('#'+R.div_id).css('top'));
			var DragStart = function (e){
				new_left=old_top+parseInt(e.clientX)-x+'px';
				new_top=old_left+parseInt(e.clientY)-y+'px';
				$('#'+R.div_id).css('left',new_left);
				$('#'+R.div_id).css('top',new_top);
			};
			var DragEnd = function(){
				$('#'+R.div_id).css('opacity','1'); 
				$('#'+R.div_id).css('filter','Alpha(Opacity=100)');
				$(document).unbind('mousemove',DragStart);
				$(document).unbind('mouseup',DragEnd); 
			} 
			$(document).mousemove(DragStart);
			$(document).mouseup(DragEnd);
		});
	}
	removeIt = function(e){
		if (R.selecthide){
			$('select').show();
		}
		R.func(e);
		$('#'+R.div_id).remove();
 		$('#'+R.background_id).remove();
	}; 
	$('#remove_img').click(removeIt);
	
	/*获得反馈信息*/
	contentMss = function(){
		return R.content;
	}
	
	/*获得外部数据内容*/
	getsources = function(){
		return R.datasources;
	}
	
	getproid = function(e,t){
		R.func2(e,t);
	}
	
}
 
 //
//function remove_child(id){
//	$('#'+id).hide('slow',function(){$('#'+id).remove()});
//	$('#background_div_'+id).remove();
//	$('select').show();
//}

//中文截取函数
function subString(str, len, hasDot) 
{ 
    var newLength = 0; 
    var newStr = ""; 
    var chineseRegex = /[^\x00-\xff]/g; 
    var singleChar = ""; 
    var strLength = str.replace(chineseRegex,"**").length; 
    for(var i = 0;i < strLength;i++) 
    { 
        singleChar = str.charAt(i).toString(); 
        if(singleChar.match(chineseRegex) != null) 
        { 
            newLength += 2; 
        }     
        else 
        { 
            newLength++; 
        } 
        if(newLength > len) 
        { 
            break; 
        } 
        newStr += singleChar; 
    } 
     
    if(hasDot && strLength > len) 
    { 
        newStr += "..."; 
    } 
    return newStr; 
} 

/*模拟php中的in_array*/
function in_array(needle, haystack) {
  if(typeof needle == 'string' || typeof needle == 'number') {
    for(var i in haystack) {
      if(haystack[i] == needle) {
          return true;
      }
    }
  }
  return false;
}


/**
 *@info 获取url参数
 *@author: HJ
 *@date: 2010-09-07
 *@param string fieldName 参数名称
 *@return 参数或者null
 * */
function QueryString(fieldName)
{ 
	  var urlString = document.location.search;
	  if(urlString != null)
	  {
	       var typeQu = fieldName+"=";
	       var urlEnd = urlString.indexOf(typeQu);
	       if(urlEnd != -1)
	       {
	            var paramsUrl = urlString.substring(urlEnd+typeQu.length);
	            var isEnd =  paramsUrl.indexOf('&');
	            if(isEnd != -1)
	            {
	                 return paramsUrl.substring(0, isEnd);
	            }
	            else
	            {
	                return paramsUrl;
	            }
	       }
	       else
	       {
	            return null;
	       }
	  }
	 else
	 {
	    return null;
	 }
}

/**
 *@info 取窗口滚动条高度
 *@author: HJ
 *@date: 2010-09-07
 *@param null
 *@return 滚动条高度
 * */
function getScrollTop()
{
    var scrollTop=0;
    if(document.documentElement&&document.documentElement.scrollTop)
    {
        scrollTop=document.documentElement.scrollTop;
    }
    else if(document.body)
    {
        scrollTop=document.body.scrollTop;
    }
    return scrollTop;
}

/**
 *@info 取窗口可视范围的高度
 *@author: HJ
 *@date: 2010-09-07
 *@param null
 *@return 窗口可视范围的高度
 * */
function getClientHeight()
{
    var clientHeight=0;
    if(document.body.clientHeight&&document.documentElement.clientHeight)
    {
        var clientHeight = (document.body.clientHeight<document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;       
    }
    else
    {
        var clientHeight = (document.body.clientHeight>document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;   
    }
    return clientHeight;
}

/**
 *@info 取文档内容实际高度
 *@author: HJ
 *@date: 2010-09-07
 *@param null
 *@return 文档内容实际高度
 * */
function getScrollHeight()
{
    return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
}

/**
* @info 热键 Ctrl+S 保存 Ctrl+Enter 保存并继续
* @author HJ 
* @date 2011-01-14 添加注释
 * @param e 时间对像
 * @return true or false
*/
function hotkey(e) 
{ 
	/*判断浏览器*/
	var ex = navigator.appName;
	
	if (ex=='Microsoft Internet Explorer'){
		kc = window.event.keyCode;
		
		if((event.ctrlKey) &&(kc==83)){
			postEvent(false);
			return false;
		}
		
		if((event.ctrlKey) &&(kc==13)){
			postEvent(true);
			return false;
		}
		
	}else{
		kc = e.which; 
		
		if((e.ctrlKey) &&(kc==83)){
			postEvent(false);
			return false;
		}
		
		if((e.ctrlKey) &&(kc==13)){
			postEvent(true);
			return false;
		}
	}

}

/**
* @info 严格验证手机号和长度开头第一个不是1的返回true长度不够11的返回true
* @author HJ 
* @date 2011-01-14 添加注释
* @param string val 输入的内容
* @return true or false
*/
function checkSimpleMobile(val){

	if (isNaN(val)){
		return true;
	}
	
	var fT = '';
	var fL = '';
	
	val = val.toString();
	
	fT = val.substr(0,1);
	fL = val.length;

	if(fT=='1'){
		if(fL<11||fL>11){
			return true;		
		}else{
			return false;
		}
	}else{
		return true;
	}
}


/* 
Correctly handle PNG transparency in Win IE 5.5 & 6.
Copyright 2007 Ignia, LLC
Based in part on code from from http://homepage.ntlworld.com/bobosola.

Use in <HEAD> with DEFER keyword wrapped in conditional comments:
<!--[if lt IE 7]>
<script defer type="text/javascript" src="pngfix.js"></script>
<![endif]-->

*/

function fixPng() {

  var arVersion = navigator.appVersion.split("MSIE")
  var version = parseFloat(arVersion[1])

  if ((version >= 5.5 && version < 7.0) && (document.body.filters)) {
    for(var i=0; i<document.images.length; i++) {
      var img = document.images[i];
      var imgName = img.src.toUpperCase();
      if (imgName.indexOf(".PNG") > 0) {
        var width = img.width;
        var height = img.height;
        var sizingMethod = (img.className.toLowerCase().indexOf("scale") >= 0)? "scale" : "image"; 
        img.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img.src.replace('%23', '%2523').replace("'", "%27") + "', sizingMethod='" + sizingMethod + "')";
        img.src = ""+themeUrl+"misc/images/new/blank.gif";
       
        img.width = width;
        img.height = height;
        }
      }
    }
  }


/**
* @info 为所有的input和textarea绑定onKeyUp和blur事件
* @author HJ 
* @date 2011-04-25 
* @param array numberArr 必须为数字指定的字段名称
* @param array numberArrs 必须为数字指定的动态字段名称
* @param array ccounts 配合动态字段名称的出现个数
* @return null
*/
function colationsp(numberArr,numberArrs,ccounts){
	
	var numberArr = numberArr;

	var numberArrs = numberArrs;

	var ccounts = ccounts;
	
	$('* input,textarea').keyup(function(e){
		
		fnbody(this);

	}).blur(function(e){

		fnbody(this);
		
	});
	
	
	function fnbody(obj){
	
		var reg = /[\\\/\*\?"<>,|&%'`~]/g;
		
		if (in_array($(obj).attr('id'),numberArr)){
		
			reg = /[\D]/g;
		}

		if (ccounts == 0){
			
			for (var j =0;j < numberArrs.length;j ++){
				if ($(obj).attr('id') == numberArrs[j]+"0"){
					reg = /[\D]/g;
				}
			}
			
		}else if (ccounts > 0){

			for (var i = 0;i < (ccounts+1);i ++){
				
				for (var j =0;j < numberArrs.length;j ++){
					if ($(obj).attr('id') == numberArrs[j]+[i]){
						reg = /[\D]/g;
					}
				}
			
			}
		}
		
		$(obj).val($(obj).val().replace(reg,"")); 
		
	}
}


/**
 *@info 将所有输入框加上过滤函数
 *@author: HJ
 *@date: 2012-03-02
 *@param null
 *@return null
 * */
$('#mid input,textarea').each(function(){

	var id = $(this).attr('id');

	if ( id != '' )
	{
		$('#'+id).keyup(function(){
			
			return fnInputFilterFCC2(this);
			
		}).focus(function(){
			
			return fnInputFilterFCC2(this);
			
		}).blur(function(){
			
			return fnInputFilterFCC2(this);
			
		});
	}
	
});